<?
include 'includes/specs_functions.php';
echo printGoogleAnalytics();
#------------------------------------------------------------------------
# Connect to PADS
$DB = getDB();
#-------------------------------$Session information
$SESSION = get_session($DB);
$userCICUID = $SESSION->Character;
$THEME = $_POST["THEME"];
$userAVATAR = $SESSION->GetCharacter('avatar');
$padCICUID = $_POST['CICUID'];
$padAVATAR = $_POST['AVATAR'];
#---------------------------------------------------
//Show($SESSION->GetCharacter('id'));
//Show($SESSION->GetCharacter('avatar'));

$sId = $_POST['specId'];
$amount = $_POST['amount'];

//$padCICUID = 9545338;  // Nemi Chan

if (isset($_POST['specId']) && isset($_POST['amount'])){

	$output = "
				<script type='text/javascript'>
					
					$(document).ready(function(){
						$('.more-comment').click(function(e) {
							loadWidgetComments(".$sId.",".($amount+5).");
						});
					});
				</script>
				<table style='width:100%'>";
				
					
				$abfrage = "
					   SELECT user.".TBL_CHARACTERS_CICUID." as uId
					   ,comm.".SPEC_TBL_COMMENTS_ID." as id
					   ,comm.".SPEC_TBL_COMMENTS_SPEC_ID." as specId
					   ,comm.".SPEC_TBL_COMMENTS_COMMENT." as comment
					   ,DATE_FORMAT(comm.".SPEC_TBL_COMMENTS_UDATE.",'%b %d %Y') as c_udate
					   ,user.".TBL_CHARACTERS_NAME." as Name
					   ,user.".TBL_CHARACTERS_AVATAR." as Avatar
					   ,'' as value
					   ,'COMM' as type 
				FROM (
				".SPEC_TBL_COMMENTS." as comm 
				LEFT JOIN ".TBL_CHARACTERS." as user
				ON user.".TBL_CHARACTERS_CICUID." = comm.".SPEC_TBL_COMMENTS_USER_ID.")		
				WHERE comm.".SPEC_TBL_COMMENTS_SPEC_ID." = \"".$sId."\"
				ORDER BY DATE_FORMAT(comm.".SPEC_TBL_COMMENTS_UDATE.",'%b %d %Y') DESC";

				$result = $DB->RawQuery($abfrage);

				$num = $result[0];	
				$i = 1;
					
				if($num>0){
					foreach ($result[2] as $row) {
						$MyAvatar = "<div class='border-av'><img class='avatar-pic' style='width:36px;' src='".$row['Avatar']."?".time()."'/></div>";

			$output .= "<tr class='border-bottom' >
							<td class='ver-top cur-point' style='border-bottom: solid 1px #F4F4F4;' width='22%'>
								<a class='cur-point' name='no' href='?".$row['uId']."'>".$MyAvatar."</a>
							</td>
							<td class='td-table ver-top' style='border-bottom: solid 1px #F4F4F4;' width='78%'>
								<div>
									<a class='cur-point bold-text' name='no' style='font-size:10px' href='?".$row['uId']."'>".$row['Name']."</a>
								</div>
								<div class='normal-text' style='overflow: hidden;white-space: pre-wrap;margin-top: 2px;margin-left: 5px;'>".$row['comment']."</div>
								<div class='normal-text font-10 fl-left'>
										<div class='op-4 fl-left' style='padding-bottom:5px; padding-right:5px;padding-top: 2px;'>".$row['c_udate']."</div>
								</div>
							</td>
						</tr>";
							if($i == $amount){
							break;
						}
						$i++;
					}
				}
				
				
				if($i<$num){
					// MORE COMMENTS TO SHOW
					$output .= "<tr>
						<td  colspan='2' style='text-align: center;padding-top: 10px;'>
							<div class='more-comment center cur-point arrow-down' style='display:inline;'/>
						</td>
					</tr>";
					
				}
			
		$output .= "</table><div style='clear:both;'>";

	echo  $output;
}

#------------------------------------------------------------------------
# Disconnect
leaveDB($DB);

?>